package com.winit.core.host.code;

import com.winit.common.util.ShellRunUtil;
import com.winit.core.host.code.beans.OperateParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wangjian on 16/7/22.
 * 操作svn
 */
public class SvnOperatorListener implements CodeOperator.Listener{
    private static final Logger logger = LoggerFactory.getLogger(SvnOperatorListener.class);

    @Override
    public Map<String, String> checkOut(OperateParam operateParam) {
        Map<String,String> map = new HashMap<>();
        String[] param = new String[4];
        param[0] = "svn";
        param[1] = "checkout";
        param[2] = operateParam.getRemotePath()+"@HEAD";
        param[3] = operateParam.getLocalPath();
        ShellRunUtil.runShell(param);
        map.put("code","0");
        return map;
    }

    @Override
    public Map<String, String> commit(OperateParam operateParam) {
        Map<String,String> map = new HashMap<>();
        String[] param = new String[5];
        param[0] = "svn";
        param[1] = "commit";
        param[2] = "-m";
        param[3] = "\""+operateParam.getDesc()+"\"";
        param[4] = operateParam.getLocalPath();
        ShellRunUtil.runShell(param);
        map.put("code","0");
        return map;
    }

    @Override
    public Map<String, String> update(OperateParam operateParam) {
        Map<String,String> map = new HashMap<>();
        String[] param = new String[5];
        param[0] = "svn";
        param[1] = "update";
        param[2] = "--accept";
        param[3] = "mine-full";
        param[4] = operateParam.getLocalPath();
        ShellRunUtil.runShell(param);
        map.put("code","0");
        return map;
    }
}
